home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / FFT and Complex Numbers Library / FFTLibrary.sit / FFT library ƒ / FFT.h < prev    next >
Text File  |  1995-01-15  |  4KB  |  126 lines

  1. //
  2. //    File: FFT.h
  3. //    Copyright ⌐1994-1995 James Wilson
  4. //    All rights reserved.
  5. //    
  6. //    This is the header file for FFT.cp, an implementation of the Fast
  7. //    Fourier Fransform (FFT).
  8.  
  9. #ifndef __FFT__
  10. #define __FFT__
  11.  
  12. #if macintosh
  13.     #if defined(powerc)
  14.         #include <math.h>
  15.     #else
  16.         #if defined(__SC__)
  17.             #if __option(mc68881)
  18.                 #include <math.h>
  19.             #else
  20.                 #ifndef __SANE__
  21.                     #include <SANE.h>
  22.                 #endif
  23.             #endif
  24.         #else
  25.             #include <math.h>
  26.         #endif
  27.     #endif
  28. #else
  29.     #include <math.h>
  30. #endif
  31.  
  32. #ifndef __COMPLEXNUMBERS__
  33. #include "ComplexNumbers.h"
  34. #endif
  35.  
  36. // 2*pi is equal to one revolution in radians (equivalent to 360 degrees).
  37. const double twoPi = 6.28318530717959;
  38.  
  39. typedef Complex *ComplexArray;
  40.  
  41. /*
  42.     Function name: FFT
  43.     
  44.     Returns: none
  45.     
  46.     Parameters:
  47.         n:    the number of data points in the spectrumOut array. n should
  48.             always be a power of 2.
  49.         nu:    nu should satisfy this equation: n = 2^nu. ^ signifies power
  50.             not the binary XOR operator. In other words, nu is log2 of
  51.             n.
  52.         spectrumOut: on input, the real fields of the elements in this
  53.             array should hold the input values of the time-waveform to
  54.             be analyzed, with all the imaginary fields set to 0. On
  55.             output, this array holds the complex values of the Fourier
  56.             transform of the input. Input data is destroyed.
  57.     
  58.     Notes:    This function is an implementation of the Fast Fourier
  59.             transform, a function that takes any sampled function and
  60.             breaks in up into sine and cosine components. It is
  61.             particularly useful in digital signal processing and the
  62.             analysis of sound waves.
  63. */
  64. extern void FFT(const long n, const long nu, ComplexArray spectrumOut);
  65.  
  66. /*
  67.     Function name: IFFT
  68.     
  69.     Returns: none
  70.     
  71.     Parameters:
  72.         n and nu:    these variables serve the same purpose as they do
  73.                     in the function FFT (see above).
  74.         functionOut:On input, the elements of this array should hold the
  75.                     complex Fourier transform values that are to be
  76.                     transformed back into function values.
  77.     
  78.     Notes:    This function performs an Inverse Fourier transform; it takes
  79.             the transform values and creates a function out of it. The
  80.             IFFT is defined seperately from the FFT for pure computational
  81.             speed. Please be aware that the inverse values may not equal
  82.             the original values exactly. This is because anything that
  83.             uses the transcendental functions (sine, cosine, etc.) will
  84.             never be exact, however the inverse values should close
  85.             enough not to notice a significant difference.
  86. */
  87. extern void IFFT(const long n, const long nu, ComplexArray functionOut);
  88.  
  89. /*
  90.     Function name: BitReverse
  91.     
  92.     Returns: long
  93.         Possible return values: theNum, with its binary digits reversed.
  94.     
  95.     Parameters:
  96.         theNum:    the number that is to be reversed.
  97.         nu:        the number of significant bits in theNum. This paramter
  98.                 is similar to the nu paramter in the FFT function (see
  99.                 above).
  100.     
  101.     Notes:    This function produces a number that is the binary reverse of
  102.             the input, theNum. For example, calling BitReverse with
  103.             theNum = 011001 and nu = 6 results with 100110. This function
  104.             is used internally by the function FFT.
  105. */
  106. extern long BitReverse(const long theNum, const long nu);
  107.  
  108. /*
  109.     Function name: LongPower
  110.     
  111.     Returns: long
  112.         Possible return values: base, raised to the power exp.
  113.     
  114.     Parameters:
  115.         base:    the base that is to be raised by exp.
  116.         exp:    the exponent.
  117.     
  118.     Notes:    Power functions are not well defined in C/C++, so for
  119.             simplicity and compatibility, I define my own. Its operation
  120.             is staightforward, and probably not of that much interest to 
  121.             applications.
  122. */
  123. extern long LongPower(const long base, const long exp);
  124.  
  125. #endif
  126.